package uml.behavioral.interpreter;

import uml.behavioral.interpreter.exception.IllegalInstructionException;

/**
 * 解释器--终结符表达式<br>
 * on 2022/12/31 0:24
 */
public class DistanceNode extends AbstractNode {
    private String distance;

    public DistanceNode(String distance) {
        this.distance = distance;
    }

    @Override
    public String interpret() throws IllegalInstructionException {
        try {
            if (this.distance.contains(".")) {
                Float.valueOf(this.distance);
            } else {
                Integer.valueOf(this.distance);
            }
        } catch (NumberFormatException exception) {
            throw new IllegalInstructionException("无效指令" + this.distance);
        }
        return this.distance;
    }
}
